import App from '@/common/js/app.js'

const api_guahao_addorder = function (userOpenid, formData) {
	return new Promise((resolve, reject) => {
		console.log('api_guahao_addorder')
		App._post_form2("entry/wxapp/apiregistration.guahao_addorder", {
			"openid": userOpenid,
			"form": formData
		}, (res) => {
			resolve(res)
		})
	})
}

const api_guahao_icbcpay = function (userOpenid, ordersn, money) {
	return new Promise((resolve, reject) => {
		console.log('api_guahao_icbcpay')
		App._post_form2("entry/wxapp/apiregistration.guahao_icbcpay", {
			"openid": userOpenid,
			"ordersn": ordersn,
			"money": money
			// "money": 1
		}, (res) => {
			resolve(res)
		})
	})
}

const pay = function (orderInfo) {
	return new Promise((resolve, reject) => {
		// uni.getProvider({
		// 	service: 'payment',
		// 	success(res) {
		// 		console.log(res)
		// 		if (res.provider.indexOf('wxpay') > -1) {
		// 			console.log('开始支付')
		// 			uni.requestPayment({
		// 				"provider": "wxpay", //固定值为"wxpay"
		// 				"timeStamp": orderInfo.timestamp,
		// 				"nonceStr": orderInfo.noncestr,
		// 				"package": orderInfo.package,
		// 				"signType": orderInfo.signtype,
		// 				"paySign": orderInfo.sign,
		// 				success: (res) => {
		// 					resolve(res)
		// 				},
		// 				fail: (err) => {
		// 					reject(err)
		// 				}
		// 			});
		// 		}
		// 	}
		// })
		uni.requestPayment({
			"provider": "wxpay", //固定值为"wxpay"
			"timeStamp": orderInfo.timestamp,
			"nonceStr": orderInfo.noncestr,
			"package": orderInfo.package,
			"signType": orderInfo.signtype,
			"paySign": orderInfo.sign,
			success: (res) => {
				resolve(res)
			},
			fail: (err) => {
				reject(err)
			}
		});
	})
}

const api_guahao_paysucc = function (userOpenid, id, order_id) {
	return new Promise((resolve, reject) => {
		App._post_form2("entry/wxapp/apiregistration.guahao_paysucc", {
			"openid": userOpenid,
			"id": id,
			// "paytime": "",
			"order_id": order_id
		}, (res) => {
			resolve(res)
		})
	})
}

const api_reg = function (userOpenid, orderid, formData) {
	return new Promise((resolve, reject) => {
		App._post_form2("entry/wxapp/apiregistration.reg", {
			"openid": userOpenid,
			"orderid": orderid,
			"form": formData
		}, (res) => {
			resolve(res)
		})
	})
}

export default {
	api_guahao_addorder,
	api_guahao_icbcpay,
	pay,
	api_guahao_paysucc,
	api_reg
}

